<?php

namespace app\order\model;

use think\model\relation\BelongsTo;
use Throwable;
use think\Model;
use think\facade\Db;

/**
 * OrderShip模型
 */
class OrderShip extends Model
{
    protected $autoWriteTimestamp = false;
    protected $updateTime         = false;

    /**
     * 追加属性
     */
    protected $append = [
        'shop_name_arr',
    ];

    public function getShopNameArrAttr($value, $row): array
    {
        return Db::name('shops')
            ->where('id', $row['shop_id'])
            ->column('name');
    }

    public function getCreateTimeAttr($value): string
    {
        return $value ? date('Y-m-d H:i:s', $value) : '';
    }

    public function infos(): BelongsTo
    {
        return $this->belongsTo(OrderInfo::class, 'order_id', 'order_id');
    }

    public function appends(): BelongsTo
    {
        return $this->belongsTo(OrderAppend::class, 'order_id', 'order_id');
    }

    public function orders(): BelongsTo
    {
        return $this->belongsTo(Order::class, 'order_id', 'order_id');
    }

}